//
//  ViewController.m
//  ZFHorizontalMenuView
//
//  Created by linzaifei on 2021/9/3.
//

#import "ViewController.h"
#import "ZFHorizontalMenuView.h"
#import "colors.h"
@interface ViewController ()
{
    int i ;
}
@end

@implementation ViewController

//
//- (void)viewDidLoad
//{
//    [super viewDidLoad];
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(60,60, 100, 300)];
//    view.tag = 100;
//    [self.view addSubview:view];
//    [view setBackgroundColor:[UIColor grayColor]];
//    i = 0;
//}
//
//- (void)didReceiveMemoryWarning
//{
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}
//-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
////    UITouch *touch = [touches anyObject];
////    UIView *vi = [touch view];
//    if (i==0) {
//        UIView *v = [self.view viewWithTag:100];
//        [v setTag:100];
//        [UIView animateWithDuration:0.5 animations:^{
//            [v setFrame:CGRectApplyAffineTransform(CGRectMake(v.frame.origin.x, v.frame.origin.y, v.frame.size.width,10), CGAffineTransformMakeTranslation(0, v.frame.size.height))];
//            //code
//        }];
//        i = 1;
//    }
//    else if(i==1)
//    {
//        UIView *v = [self.view viewWithTag:100];
//        [v setTag:100];
//        [UIView animateWithDuration:0.5 animations:^{
//            [v setFrame:CGRectApplyAffineTransform(CGRectMake(v.frame.origin.x, v.frame.origin.y, v.frame.size.width, 300), CGAffineTransformMakeTranslation(0, -300))];
//            //code
//        }];
//        i = 0;
//    }
//}
//








- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexLightColor:COLOR_BG darkColor:COLOR_BG];

    NSArray *arr = @[@"样式一",@"自定义text",@"自定义cell",];
    NSMutableArray *btns = [NSMutableArray array];

    NSString *str = @"V:|-100-";
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    for (int i = 0; i< arr.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:arr[i] forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor orangeColor];
        btn.titleLabel.textColor = [UIColor whiteColor];
        btn.tag = 100+i;
        [self.view addSubview:btn];
        [btns addObject:btn];
        [btn addTarget:self action:@selector(onClickItem:) forControlEvents:UIControlEventTouchUpInside];

        btn.translatesAutoresizingMaskIntoConstraints = NO;

        if (i==arr.count-1) {
            str = [str stringByAppendingFormat:@"[btn%d(==50)]",i];
        }else{
            str = [str stringByAppendingFormat:@"[btn%d(==50)]-30-",i];
        }
        [dic setValue:btn forKey:[NSString stringWithFormat:@"btn%d",i]];

        NSString *horStr = [NSString stringWithFormat:@"H:|-50-[btn%d]-50-|",i];
        NSArray *arr = [NSLayoutConstraint constraintsWithVisualFormat:horStr options:0 metrics:0 views:@{[NSString stringWithFormat:@"btn%d",i]:btn}];
        [self.view addConstraints:arr];
    }



    NSArray<NSLayoutConstraint *> *layouts = [NSLayoutConstraint constraintsWithVisualFormat:str options:0 metrics:0 views:dic];
    [self.view addConstraints:layouts];

}

-(void)onClickItem:(UIButton *)button{
    NSInteger index = button.tag-100;
    if (index==0) {
        [self.navigationController pushViewController:[[NSClassFromString(@"MenuViewController") alloc] init] animated:YES];
    }else if (index==1) {
        [self.navigationController pushViewController:[[NSClassFromString(@"Menu1ViewController") alloc] init] animated:YES];
    }else if (index==2) {
        [self.navigationController pushViewController:[[NSClassFromString(@"Menu2ViewController") alloc] init] animated:YES];
    }

}







@end
